﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows.Forms;

namespace 护士工作站
{
    public partial class 在院病人信息查询 : Form
    {
        public 在院病人信息查询()
        {
            InitializeComponent();
        }
    
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "内科")
                {
                    string m = "select PatName,InHospital.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='内科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();
                        DataSet ds = new DataSet();
                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)

                if (this.treeView1.SelectedNode.Text == "外科")
                {
                    string m = "select PatName,InHospital.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='外科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();
                        DataSet ds = new DataSet();
                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);

                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "妇产科")
                {
                    string m = "select PatName,InHospital.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='妇产科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();
                        DataSet ds = new DataSet();
                        da = new SqlDataAdapter(m, conn);

                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "儿科")
                {
                    string m = "select PatName,InHospital.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='儿科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "五官科")
                {
                    string m = "select Patient.PatName,Patient.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='五官科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)

                if (this.treeView1.SelectedNode.Text == "肿瘤科")
                {
                    string m = "select PatName,InHospital.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='肿瘤科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);
                        DataSet ds = new DataSet();
                        da.Fill(ds);

                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "中医科")
                {
                    string m = "select PatName,InHospital.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='中医科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
            foreach (TreeNode node in this.treeView1.Nodes)
                if (this.treeView1.SelectedNode.Text == "传染科")
                {
                    string m = "select PatName,InHospital.HosNo,InHospital.BedNo from Patient,InHospital where Patient.HosNo=InHospital.HosNo and InHospital. HosDepartment='传染科'";
                    using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                    {
                        SqlDataAdapter da = new SqlDataAdapter();

                        da = new SqlDataAdapter(m, conn);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        dGV1.DataSource = ds.Tables[0];
                    }
                }
        }



       
     

        private void tb_cx_KeyPress(object sender, KeyPressEventArgs e)
        {


            if (e.KeyChar == 13)
            {
                if (rb_zyh.Checked)
                {
                    if (tb_cx.Text != "")
                    {
                        for (int i = 0; i < dGV1.RowCount-1; i++)
                        {
                            if (dGV1.Rows[i].Cells[1].Value.ToString().Trim() == tb_cx.Text)
                            {
                                dGV1.CurrentCell = this.dGV1.Rows[i].Cells[1];
                                dGV1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                                string m = "select * from InHosPatient where InHosPatient.HosNo='"+this .tb_cx .Text +"'";
                               using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                               {
                                   SqlDataAdapter da = new SqlDataAdapter();

                                   da = new SqlDataAdapter(m, conn);
                                   DataSet ds = new DataSet();
                                   da.Fill(ds, "InHosPatient");
                                   CrXinxi  crReportDocument = new CrXinxi();
                                   crReportDocument.SetDataSource(ds);
                                   crystalReportViewer1.ReportSource = crReportDocument;
                               }

                            }
                        }
                    }
                    }

                if (rb_ch.Checked)
                {
                    if (tb_cx.Text != "")
                    {
                        for (int i = 0; i < dGV1.RowCount - 1; i++)
                        {
                            if (dGV1.Rows[i].Cells[2].Value.ToString().Trim() == tb_cx.Text)
                            {
                                dGV1.CurrentCell = this.dGV1.Rows[i].Cells[2];
                                dGV1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                                string m = "select * from InHosPatient where InHosPatient.BedNo='" + this.tb_cx.Text + "'";
                                using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                                {
                                    SqlDataAdapter da = new SqlDataAdapter();

                                    da = new SqlDataAdapter(m, conn);
                                    DataSet ds = new DataSet();
                                    da.Fill(ds, "InHosPatient");
                                    CrXinxi crReportDocument = new CrXinxi();
                                    crReportDocument.SetDataSource(ds);
                                    crystalReportViewer1.ReportSource = crReportDocument;
                                }

                            }
                        }
                    }
                }


                if (rb_xm.Checked)
                {
                    if (tb_cx.Text != "")
                    {
                        for (int i = 0; i < dGV1.RowCount - 1; i++)
                        {
                            if (dGV1.Rows[i].Cells[0].Value.ToString().Trim() == tb_cx.Text)
                            {
                                dGV1.CurrentCell = this.dGV1.Rows[i].Cells[0];
                                dGV1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                                string m = "select * from InHosPatient where InHosPatient.PatName='" + this.tb_cx.Text + "'";
                                using (SqlConnection conn = new SqlConnection(DBHelper.connString))
                                {
                                    SqlDataAdapter da = new SqlDataAdapter();

                                    da = new SqlDataAdapter(m, conn);
                                    DataSet ds = new DataSet();
                                    da.Fill(ds, "InHosPatient");
                                    CrXinxi crReportDocument = new CrXinxi();
                                    crReportDocument.SetDataSource(ds);
                                    crystalReportViewer1.ReportSource = crReportDocument;
                                }

                            }
                        }
                    }
                }

                }
        
            

            }

        private void tSButton_tc_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void dGV1_SelectionChanged(object sender, EventArgs e)
        {
            string b = Convert.ToString(this.dGV1[1, dGV1.CurrentCell.RowIndex].Value).Trim();
            string m = "select * from InHosPatient where InHosPatient.HosNo='" + b + "'";
            using (SqlConnection conn = new SqlConnection(DBHelper.connString))
            {
                SqlDataAdapter da = new SqlDataAdapter();

                da = new SqlDataAdapter(m, conn);
                DataSet ds = new DataSet();
                da.Fill(ds, "InHosPatient");
                CrXinxi crReportDocument = new CrXinxi();
                crReportDocument.SetDataSource(ds);
                crystalReportViewer1.ReportSource = crReportDocument;
            }
        }

       

       



        }
    }

